<!--
 * @Description: 资讯发布
 * @Author: charles
 * @Date: 2021-11-18 11:15:11
 * @LastEditors: charles
 * @LastEditTime: 2021-11-18 11:50:57
-->
<template>
  <div class="article_publish">
    <div class="container">
      <h2>
        {{form.id?"资讯修改":"资讯发布"}}
      </h2>
      <el-form :model="form" size="small">
        <el-form-item label="标题">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="栏目">
          <el-select v-model="form.categoryId">
            <el-option 
              v-for="c in categories" 
              :label="c.name"
              :value="c.id"
              :key="c.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容">
          <el-input v-model="form.content" type="textarea" :rows="4"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="submit" @click="submitHandler">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import {useStore} from 'vuex'
import {useRouter,useRoute} from 'vue-router'
import {computed,ref} from 'vue'
import {post} from '../utils/request'
import {ElMessage} from 'element-plus'
export default {
  setup() {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
   
    const form = ref(route.params)
    
    const categories = computed(()=>{ return store.state.categories })

    const submitHandler = ()=>{
      let url = "/article/saveOrUpdate"
      post(url,form.value).then(resp => {
        ElMessage({message:resp.message,type:"success"})
        router.go(-1)
      })
    }





    return {
      categories,
      form,
      submitHandler
    }
  },
}
</script>
<style lang="scss" scoped>
.article_publish {
  .container {
    width: 80%;
    margin: 0 auto;
  }
}
</style>
